//
//  NewHotAndFondCell.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/1.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class NewHotAndFondCell: UICollectionViewCell {
    
    // MARK: - life cycle
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initBaseLayout()
        layoutPageSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MAKR: - private method
    func initBaseLayout() {
        self.backgroundColor = UIColor.white
        self.addSubview(iconImageView)
        self.addSubview(brandLabel)
        self.addSubview(productLabel)
        self.addSubview(priceLabel)
        self.addSubview(originalPriceLabel)
    }
    
    func layoutPageSubviews() {
        iconImageView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
//            make.left.equalTo(self).offset(14)
            make.top.equalTo(self).offset(0)
            make.width.size.equalTo(162)
        }
        
        brandLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
//            make.left.equalTo(self).offset(13)
            make.top.equalTo(iconImageView.snp.bottom).offset(10)
            make.width.equalTo(162)
            make.height.equalTo(13)
        }
        
        productLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
//            make.left.equalTo(self).offset(12)
            make.top.equalTo(brandLabel.snp.bottom).offset(6)
            make.width.equalTo(162)
            make.height.equalTo(12)
        }
        
        priceLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(11)
            make.top.equalTo(productLabel.snp.bottom).offset(9)
            make.width.equalTo(62)
            make.height.equalTo(12)
        }
        
        originalPriceLabel.snp.makeConstraints { (make) in
            make.left.equalTo(priceLabel.snp.right).offset(1)
            make.top.equalTo(productLabel.snp.bottom).offset(9)
            make.width.equalTo(62)
            make.height.equalTo(12)
        }
    }
    
    func configUI(bestListModel: ListOfGoodsModel) {
        
        iconImageView.sd_setImage(with: URL(string: bestListModel.mainPicUrl!), placeholderImage: UIImage(named: "def_162x162"))
        
        brandLabel.text = bestListModel.brandName
        productLabel.text = bestListModel.title
        priceLabel.text = "￥" + "\(bestListModel.rmbPrice!)"
        originalPriceLabel.text = "￥" + "\(bestListModel.marketPrice!)"
    }
    
    // MARK: - setters and getters
    var _iconImageView: UIImageView!
    var iconImageView: UIImageView {
        if _iconImageView == nil {
            _iconImageView = UIImageView()
            
        }
        return _iconImageView
    }
    
    var _brandLabel: UILabel!
    var brandLabel: UILabel {
        if _brandLabel == nil {
            _brandLabel = UILabel()
            _brandLabel.font = UIFont(name: "PingFangSC-Medium", size: 13)
            _brandLabel.textColor = UIColor(hexString: "#252525")
        }
        return _brandLabel
    }
    
    var _productLabel: UILabel!
    var productLabel: UILabel {
        if _productLabel == nil {
            _productLabel = UILabel()
            _productLabel.font = UIFont(name: "PingFangSC-Light", size: 13)
            _productLabel.textColor = UIColor(hexString: "#666666")
        }
        return _productLabel
    }
    
    var _priceLabel: UILabel!
    var priceLabel: UILabel {
        if _priceLabel == nil {
            _priceLabel = UILabel()
            _priceLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _priceLabel.textColor = UIColor(hexString: "#252525")
        }
        return _priceLabel
    }
    
    var _originalPriceLabel: UILabel!
    var originalPriceLabel: UILabel {
        if _originalPriceLabel == nil {
            _originalPriceLabel = UILabel()
            _originalPriceLabel.font = UIFont(name: "PingFangSC-Light", size: 12)
        }
        return _originalPriceLabel
    }
}

